﻿using LPP.Core.Dtos;
using LPP.Entity.Work;
using LPP.EntityFrameworkCore;
using LPP.Repository.WorkerRepository;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LPP.Service.WorkerService
{
    public class WorkService : IWorkerService
    {
        private readonly IWorkerRepository _workerRepository; // 假设您有一个仓储接口来处理数据

        public WorkService(IWorkerRepository workerRepository)
        {
            _workerRepository = workerRepository;
        }

        public async Task RegisterWorkerAsync(WorkerDto workerDto)
        {
            // 这里可以添加输入验证逻辑，例如检查 workerDto 是否有效

            // 将 WorkerDto 转换为实体
            var workerEntity = new Worker // 假设有一个 Worker 实体
            {
                Name = workerDto.Name,
                Phone = workerDto.Phone,
                RealName = workerDto.RealName,
                IdCardNumber = workerDto.IdCardNumber,
                IdCardFront = workerDto.IdCardFront, // 期待已上传的图片URL
                IdCardBack = workerDto.IdCardBack,   // 期待已上传的图片URL
                CreatedAt = DateTime.UtcNow,
                IsVerified = false
                // 根据 WorkerDto 的属性映射其他属性
                // 例如：Email = workerDto.Email,
                // 其他属性...
            };

            // 将实体保存到数据库
            await _workerRepository.AddWorkerAsync(workerEntity);
        }
    }

}
